package com.response.controller;

import com.response.result.exception.RRException;
import com.response.service.ResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author： yu.Tan
 * @Date: 2020/11/23 14:55
 * @Description:
 */
@RestController
public class ResponseController {

    @Autowired
    private ResponseService responseService;

    @RequestMapping(value = "get_a", method = RequestMethod.GET)
    public String getA() {
        return "GET_A";
    }

    @RequestMapping(value = "get_b", method = RequestMethod.GET)
    public Integer getB() {
        return 2;
    }

    @RequestMapping(value = "get_c", method = RequestMethod.GET)
    public int getC() {
        return 2;
    }

    @RequestMapping(value = "get_d", method = RequestMethod.GET)
    public boolean getD() {
        return true;
    }

    @RequestMapping(value = "get_e", method = RequestMethod.GET)
    public List<String> getE() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("4");
        list.add("1");
        list.add("5");
        list.add("6");

        list.forEach((x)->{
            System.out.println(x);
        });
        return list;
    }

    @RequestMapping(value = "get_f", method = RequestMethod.GET)
    public Map<Integer, String> getF() {
        Map<Integer, String> map = new HashMap<>();
        map.put(1, "1");
        map.put(2, "2");
        map.put(3, "3");
        map.put(4, "4");
        return map;
    }

    @RequestMapping(value = "get_g", method = RequestMethod.GET)
    public Map<Integer, String> getG()  {

        int i = 1 / 0;

        Map<Integer, String> map = new HashMap<>();
        map.put(1, "1");
        map.put(2, "2");
        map.put(3, "3");
        map.put(4, "4");
        return map;
    }


    @RequestMapping(value = "get_h", method = RequestMethod.GET)
    public String getH()  {
       return responseService.serviceA();
    }


    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("4");
        list.add("1");
        list.add("5");
        list.add("6");

        list.forEach((x)->{
            System.out.println(x);
        });


        Map<Integer, String> map = new HashMap<>();
        map.put(1, "1");
        map.put(2, "2");
        map.put(3, "3");
        map.put(4, "4");

        map.forEach((k,v)->{
            System.out.println(k+":"+v);
        });
    }
}
